{% import "utils.html" as utils %}
<form method="POST" action="/task/{{ '%s/edit' % task.id if task else 'new' }}">
  <h2 class="text-center">私有签到框架<sup>20210628</sup></h2>
  <hr>
  {% if task.disabled %}
  <p class="alert alert-danger">任务处于禁用状态，使用 <a class="modal_load alert-link" href="/task/{{ task.id }}/run">立即执行</a> 成功签到一次，即可解除。</p>
  {% endif %}

  <div id="run-result"></div>

  <div class="form-group">
    <label class="control-label" for="site-select">
      <a id="siteurl" href="" target="_blank" style="color:black;">网站</a>
    </label>
    <select class="form-control" name="_binux_tplid">
      {% for tpl in tpls %}
      <option value="{{ tpl.id }}" {% if tpl.id == tplid %}selected{% endif %} {% if not tpl.id %}disabled{% endif %}>{{ tpl.sitename or '未命名' }}</option>
      {% endfor %}
    </select>
  </div>

  <div id="variables">
    {% include "task_new_var.html" %}
  </div>

  {% if current_user %}
  <div class="form-group">
    <label class="control-label" for="note">备注</label>
	<!-- MY页面-添加签到-增加提示语 -->
    <input type="text" class="form-control" name="_binux_note" value="{{ task.note or '' }}" id="note" placeholder="尽可能填写15个字符以内">
	<!-- MY页面-添加签到-增加备注图标 -->
	<span class="glyphicon glyphicon-file form-control-feedback" aria-hidden="true"></span>
	
  </div>
  {% endif %}

  {% if current_user %}
  <div class="form-group">
    <label class="control-label" for="proxy">代理</label>
    <!-- MY页面-添加签到-增加提示语 -->
    <input type="text" class="form-control" name="_binux_proxy" value="{{ init_env._proxy or '' }}" id="proxy" placeholder="http://127.0.0.1:8080" pattern="((https?|socks5)+://)?([^:@/]+(:[^@/]+)?@)?[^:@/]+:\d+">
    <!-- MY页面-添加签到-增加备注图标 -->
    <span class="glyphicon glyphicon-file form-control-feedback" aria-hidden="true"></span>
  </div>
  {% endif %}
  
  {% if not task and current_user %}
  <div class="checkbox">
    <label>
      <input type="checkbox" name="_binux_tested" id="tested" value="1"> 我今天已经签过到了
    </label>
  </div>
  <label class="control-label" >设置任务分组</label>
  <div class="use_redpackets_content" id="oneCheck">
    {% for group in groups %}
    <div class="checkbox">
      <label>
        <input type="checkbox" name="group-select-{{ group }} "  {% if group == groupNow %}  checked="" {% endif %}> {{ group }} 
      </label>
    </div>
    {% endfor %}
  </div>
  <div class="form-group">
    <label class="control-label" for="note">设置新分组</label>
	<!-- MY页面-添加签到-增加提示语 -->
    <input type="text" class="form-control" name="New_group" value="" id="New_group" placeholder="尽可能填写15个字符以内">
	<!-- MY页面-添加签到-增加备注图标 -->
	  <span class="glyphicon glyphicon-file form-control-feedback" aria-hidden="true"></span>
  </div>
  {% endif %}



  <div class="text-right">
    {% if task %}
    <a class="btn btn-default" data-method="POST" href="/task/{{ task.id }}/del" data-confirm="是否要删除任务?">删除</a>
    <a class="btn btn-default" data-method="POST" href="/task/{{ task.id }}/disable" data-confirm="是否禁用任务?">禁用</a>
    {% else %}
    <button id="run" data-loading-text="loading..." class="btn btn-default">测试</button>
    {% endif %}
    {% if current_user %}
    <button type="submit" data-loading-text="loading..." class="btn btn-primary">提交</button>
    {% endif %}
  </div>
  <script>
    $(function() {
      // run test
      $('#run').on('click', function() {
        var tplid = $('select[name=_binux_tplid]').val();
        var env = {};
        for (var _env=$('form').serializeArray(), i=_env.length-1; i>=0; i--) {
          env[_env[i].name] = _env[i].value;
        }
        var data = {
          env: JSON.stringify(env),
          _binux_tplid: tplid,
        }

        var $this = $(this);
        $this.button('loading');
        $.ajax('/tpl/run', {
          type: 'POST',
          data: data,
        })
        .done(function(data) {
          $('#run-result').html(data).show()
        })
        .fail(function(jxhr) {
          $('#run-result').html('<h1 class="alert alert-danger text-center">签到失败</h1><div class="well"></div>').show().find('div').text(jxhr.responseText);
        })
        .always(function() {
          $this.button('reset');
        });

        return false;
      });
    })
  </script>

  <script type="text/javascript">
    $(function () {
                var fanxiBox = $("#oneCheck input:checkbox");
                fanxiBox.click(function () {
                  if(this.checked || this.checked=='checked'){
                      fanxiBox.removeAttr("checked");
                      $(this).prop("checked", true);
                    }
                });
            });   
  </script>

  {{ utils.task_new_scripts() }}
  {{ utils.submit_loading() }}
</form>
